package com.yfht.framework.context;

import java.util.Enumeration;
import java.util.Properties;
import java.util.ResourceBundle;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.yfht.framework.context.Ctx;
import com.yfht.common.utils.PropertiesUtils;

public class ContainerListener extends ContextLoaderListener implements ServletContextListener{
	@Override	
	public void contextInitialized(ServletContextEvent event)
	  {
	    try {
	      System.out.println("*********************启动Web容器**********************");
	      String realPath = event.getServletContext().getRealPath("").replace("\\", "/");
	      PropertiesUtils.projectPath = realPath;
	      PropertiesUtils.classPath = realPath + "WEB-INF/classes/";
	      PropertiesUtils.loadBundle("aa");
	      System.out.println("*********************测试了**********************");
	      System.out.println("shimashimashima");
	      String contextPath = realPath.substring(realPath.lastIndexOf("/") + 1, realPath.length());
	      super.contextInitialized(event);
	      ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
	      Ctx.setAppContext(appContext);
	      //**读取系统基础配置
//	      PropertiesUtils.loadBundle("META-INF.config.env.app");
//	      String appInitName = PropertiesUtils.getProperty("appinit.qualified.classname");
	      //**调用初始化参数初始化系统
//	      IAppInit appInit = (IAppInit)Class.forName(appInitName).newInstance();
//	      appInit.init(PropertiesUtils.getProps(), WebApplicationContextUtils.getWebApplicationContext(event.getServletContext()));
	    } catch (Exception e) {
	      e.printStackTrace();
	    }
	  }

	  public void contextDestroyed(ServletContextEvent arg0)
	  {
		 
	  }
}
